package com.gzdh.tang.dishrecognition.mapper;

import com.gzdh.tang.dishrecognition.dto.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface DrPublicMapper {

    @Select("select zl,dinner,bm,name,price,addr,(ymonth+'-'+yday) as yday " +
            "  from ${tableName} where SAVEDM=#{savedm} and (yyear+'-'+ymonth+'-'+yday)>=#{dates} and addr=#{addr}")
    List<WeekMenuBakDto> getWeekMenuDto(@Param("tableName") String tableName,
                                        @Param("savedm") String savedm,
                                        @Param("dates") String dates,
                                        @Param("addr") int addr);

    @Select("${sql}")
    List<WeekMenuBakDto> getWeekMenuDtoSql(@Param("sql") String sql);

    @Select("select * from RESERVE where cardno=#{cardno} and dinner=#{dinner} and dcrq =#{dcrq} and cs=0")
    List<LcReportDto> getLcReport(@Param("cardno") String cardno,
                                  @Param("dinner") String dinner,
                                  @Param("dcrq") String dcrq);

    @Select("select * from reserve where cardNo = #{cardNo} and dinner = #{dinner} " +
            "and dcrq = #{date} and cs = 0 and status = 0")
    List<LcReportDto> getTakeFoodList(@Param("cardNo") String cardNo,
                                      @Param("dinner") String dinner,
                                      @Param("date") String date);

    @Update("update reserve set status = #{status},lc = #{date} where pkId in (${sqlString})")
    Integer receiveFood(@Param("status") Integer status,
                        @Param("date") String date,
                        @Param("sqlString") String sqlString);

    @Select("SELECT bm,name,addr,lbbm,mcjc,price FROM HOSMENU where status=1 and addr=#{addr}")
    List<HosMenuDto> getHosMenu(@Param("addr") int addr);

    @Select("select lbbm,lbname from MENULB")
    List<MenuLBDto> getMenuLbDto();

    @Select(" select savedm from ${table} group by SAVEDM")
    List<String> getSaveDm(@Param("table") String table);

    @Select("  select day,zl,dinner,bm,name,mcjc,price,sj,SAVEDM,pkid,addr,status from ${tableName} " +
            " where SAVEDM=#{savedm}" +
            " and (yyear+'-'+ymonth+'-'+yday)=#{date} and addr=#{addr}")
    List<NWeekMenuBakDto> getWeekMenu(@Param("tableName") String tableName,
                                      @Param("savedm") String savedm,
                                      @Param("date") String date,
                                      @Param("addr") int addr);

    @Delete("delete from ${tableName} where pkid=#{pkid}")
    int deleteNWeekMenuBakByPkid(@Param("tableName") String tableName,
                                 @Param("pkid") String pkid);

    @Insert(" insert into ${tableName} (day,zl,dinner,bm,name,mcjc,price,sj,savedm,maxnumber,imageaddress,addr,yyear,ymonth,yday,xh,lx,status) " +
            " values(#{nWeekMenu.day},#{nWeekMenu.zl},#{nWeekMenu.dinner},#{nWeekMenu.bm},#{nWeekMenu.name},#{nWeekMenu.mcjc},#{nWeekMenu.price}" +
            ",getDate(),#{savedm},999,'',#{nWeekMenu.addr},#{year},#{month},#{day},99,0,1)")
    int insertIntoWeekMenuBak(@Param("tableName") String tableName,
                              @Param("nWeekMenu") NWeekMenuBakDto nWeekMenu,
                              @Param("savedm") String savedm,
                              @Param("year") String year,
                              @Param("month") String month,
                              @Param("day") String day);


    @Select("  select count(*) as counts,sum(je) as price,sc from RESERVE where " +
            "czrq>=#{startTime} and czrq <=#{endTime} and posnum=#{posnum} and je>0 and sc in(2,3) group by sc")
    List<JiaoBanDto> getJiaoban(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("posnum") String posnum
         );
    @Select("  select count(*) as counts,sum(je) as price,sc from RESERVE where " +
            "czrq>=#{startTime} and czrq <=#{endTime} and posnum=#{posnum} and je<0 and sc in(2,3) group by sc")
    List<JiaoBanDto> getJiaoban2(@Param("startTime") String startTime, @Param("endTime") String endTime, @Param("posnum") String posnum
    );

    @Select("select count(*) as counts,sum(je) as price,sc from reserve where sc in (0,1,2,3,9) " +
            "and czrq >= #{startTime} and czrq <= #{endTime} and je ${symbol} 0 ${sqlString} group by sc")
    List<JiaoBanDto> handoverWork(Map<String, Object> params);

    @Select("select xm as userName,group1 as role from sys_user where bh = #{posnum}")
    Map<String, String> getSysUserName(@Param("posnum")String posnum);
}
